package com.xr.core.system.rabbitmq;

import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class RabbitMQProducer {

    private final RabbitTemplate rabbitTemplate;

    private final Queue queue;

    @XxlJob("rabbitMQJobHandler")
    public void sendMessage() {
        String message = "hello，rabbitmq!";
        rabbitTemplate.convertAndSend(queue.getName(), message);
        log.info("当前时间戳<{}>，生产者发送消息<{}>到testQueue队列", System.currentTimeMillis(), message);
    }

}
